<template>
    <div style="background-color: darkgreen">
        <el-main style="float:left;background-color: darkslateblue;width: 10%;height: 80%">
        </el-main>
        <el-main style="float:left;background-color: yellowgreen;height: 90%;width: 80%;">
            <router-view></router-view>
        </el-main>
    </div>
</template>

<script>


    //endpoint : "http://127.0.0.1:8088/endpoint"　
    //brokers　目录:[topic,user]
    //监听频道　文件： 自动监听sysinfo　进入监听chat
    //向目标文件写内容　wsapp/msgController/9527　=> /user/topic/chat
    //后端定时任务向目标文件写内容　schedule =>/user/topic/sysinfo
    //返回客户端msg.body like {'datetime':'2014-11-01','core'='有人在吗？'}
    //发送服务器msg.body like {'ip':'','core'='请问有人在吗？'}
    export default {

        name: "WeChat",
        components: {
            // New,Old,
        },
        data() {
            return {
                messageTemplate: null,
            }
        },
        computed: {},
        created() {
            /*
            * Client.prototype.connect = function()  headers = out[0], connectCallback = out[1], errorCallback = out[2]
            * Client.prototype.subscribe = function(destination, callback, headers)
            * Client.prototype.send = function(destination, headers, body)
            * Client.prototype.unsubscribe = function(id)
            * Client.prototype.disconnect = function(disconnectCallback, headers)
            * */
        },

        mounted() {
            this.messageTemplate = this.$messageTemplate;
            this.messageTemplate.connect({},
                (frame) => {
                    console.log("connect ok");
                    this.subPublic()
                },
                () => {
                    console.log("connect fail")
                }
            )


        },
        destroyed() {
            this.messageTemplate.disconnect(() => {
                console.log("断开链接了")
            }, {quit: true})
        },

        methods: {
            subPublic() {
                this.messageTemplate.subscribe("/notice/common", (message) => {
                    console.log(message.command)
                    console.log(message.headers)
                    this.$notify({
                        title: '系统提示：',
                        message: JSON.stringify(message.body)
                    })
                });
            },

        },
        watch: {},
    }
</script>

<style scoped>
    /*<style lang='scss' scoped>*/

</style>